<%--
  Created by IntelliJ IDEA.
  User: pc
  Date: 2020/11/11
  Time: 10:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<%-----------------------------------------------------添加员工弹出框------------------------------------%>

<div class="layui-elem-field">
    <form class="layui-form layui-form-pane" id="searchNewsFrom">
        <div class="layui-row">
            <div class="layui-inline layui-col-md-offset1">
                <label class="layui-form-label">设施类型</label>
                <div class="layui-input-block">
                    <input type="text" name="name" class="layui-input" placeholder="设施类型">

                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">设施名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="ssName" class="layui-input" placeholder="设施名称">
                </div>
                <button type="button" data-type="reload"
                        class="layui-btn layui-btn-radius layui-btn-normal layui-icon layui-icon-search"
                        lay-submit lay-filter="searchBtn">搜索
                </button>
            </div>
        </div>
    </form>
</div>


<div id="addGustForm">
    <form class="layui-form" action="" style="padding-top:50px">
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <input type="text"  name="ssName" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数量</label>
            <div class="layui-input-inline">
                <input type="text" name="ssCount" required   placeholder="请输入数量" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-inline">
            <label class="layui-form-label" >类型</label>
            <div class="layui-input-inline layui-form-item" >
                <select name="ssTypeid" required autocomplete="off">
                    <option value="">请选择类型</option>
                    <option value="1">酒店消耗品</option>
                    <option value="2">固定设施</option>
                    <option value="3">娱乐设施</option>

                </select>
            </div>

           <%-- <div class="layui-input-block">
                <input type="text" name="name" required   placeholder="请输入类型" autocomplete="off" class="layui-input">
            </div>--%>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">定价</label>
            <div class="layui-input-inline">
                <input type="text" name="ssPmoney" required   placeholder="请输入定价" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌</label>
            <div class="layui-input-inline">
                <input type="text" name="ssGys" required   placeholder="请输入品牌" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo" >立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<%----------------------------------------------------------修改 弹窗----------------------------------------------------------------------%>
<div id="updGustForm">
    <form class="layui-form" action="" lay-filter="modify" style="padding-top:20px" >
        <div class="layui-form-item">
            <label class="layui-form-label">id</label>
            <div class="layui-input-inline">
                <input type="text"  name="ssId" required  lay-verify="required" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <input type="text"  name="ssName" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数量</label>
            <div class="layui-input-inline">
                <input type="text" name="ssCount" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-inline">
                <input type="text" name="name" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">定价</label>
            <div class="layui-input-inline">
                <input type="text" name="ssPmoney" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌</label>
            <div class="layui-input-inline">
                <input type="text" name="ssGys" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo" >立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">添加</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>

<%--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" >删除</a>
<%--

    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
--%>


  <%--  &lt;%&ndash;  模板引擎  &ndash;%&gt;
    &lt;%&ndash;  判断数量 ，大于零禁用  d 代标当前这一行数据，layui规定的&ndash;%&gt;
    {{# if(d.ssCount>0) { }}
    <a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="del">删除</a>
    {{# }else { }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{# } }}
--%>
<%--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
</script>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script>
    layui.use(['table','layer','form'], function(){
        var table = layui.table;
        var layer=layui.layer;
        var $=layui.jquery;
        var form=layui.form;

        $("#addGustForm").hide();
        $("#updGustForm").hide();
        var condition = "";
        $(function () {
            showTable();
        })

        function showTable() {
            table.render({
                elem: '#test' //id为test的table
                /*分页*/
                ,limit:5
                ,limits:[5,10,15]
                ,request:{
                    pageName:'curr'
                    ,limitName:'nums'
                },
                where: {condition: condition}
               /* ,url:'${pageContext.request.contextPath}/show'*/
                ,url:'${pageContext.request.contextPath}/T_sheshiServlet?method=showTable'   //url 查询数据   所有的客户的数据
                ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    ,layEvent: 'LAYTABLE_TIPS'
                    ,icon: 'layui-icon-tips'
                }]
                ,title: '客户数据表'
                //data[{ id:12,name:123}]
                ,cols: [[
                    {field:'ssId', title:'ID',fixed: 'left',  sort: true}
                    ,{field:'ssName', title:'名称'}
                    // ,{field:'email', title:'邮箱', width:150, edit: 'text', templet: function(res){
                    //         return '<em>'+ res.email +'</em>'
                    //     }}
                    ,{field:'ssCount', title:'数量',sort: true}
                    ,{field:'name', title:'类型',sort: true}
                    ,{field:'ssPmoney', title:'定价',sort: true}
                    ,{field:'ssGys', title:'品牌',  sort: true}
                    ,{fixed: 'right', title:'操作' , toolbar: '#barDemo'}
                ]]
                ,page: true
            });
        }




        //查询的提交事件
        form.on('submit(searchBtn)', function (data) {
            condition="";
           // alert(data.field.name);
            if(data.field.name!=null && data.field.name!=="" ){
                condition += " and name like '%"+data.field.name+"%' ";
            }
            if(data.field.ssName!=null && data.field.ssName!==""){
                condition += " and ssName like '%"+data.field.ssName+"%' ";
            }
            showTable()
            return false;
        });

        //监听行工具事件  test  表格的id
        table.on('tool(test)', function(obj){
            //obj 代表 一行的内容
            var data = obj.data; //一行的数据
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    // obj.del();//页面删除
                    window.location.href="${pageContext.request.contextPath}/T_sheshiServlet?method=del&ssId="+data.ssId;
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                form.val("modify",{
                    "ssId":data.ssId,
                    "ssName":data.ssName,
                    "ssCount":data.ssCount,
                    "name":data.name,
                    "ssPmoney":data.ssPmoney,
                    "ssGys":data.ssGys,
                });
                layer.open({
                    title: '修改信息'
                    ,type:1
                    ,area: ['450px', '450px']
                    ,offset: '50px'
                    ,content:$("#updGustForm")
                });
                form.on('submit(formDemo)', function(data){
                    //layer.msg(JSON.stringify(data.field));
                    //1.将获取到到的数据保存到数据库
                    $.ajax({
                        url:"${pageContext.request.contextPath}/T_sheshiServlet?method=add",
                        data:data.field,
                        //当前表单里面填写的数据{name:'',name1:''}
                        type:"post",

                        success:function(r){
                            layer.closeAll();
                            //刷新一下table
                            table.reload('test',{
                                page:{
                                    curr:1
                                }
                            })

                        },error:function(msg){
                            alert("服务器错误")
                        }

                    })

                    return false;
                });

                /* layer.prompt({
                     formType: 2
                     ,value: data.email
                 }, function(value, index){
                     obj.update({
                         email: value
                     });
                     layer.close(index);
                 });*/
            }
        });


        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            layer.open({
                title: '添加部门'
                ,type:1
                ,area: ['450px', '450px']
                ,offset: '50px'
                ,content:$("#addGustForm")
            });
            form.on('submit(formDemo)', function(data){
                //layer.msg(JSON.stringify(data.field));
                //1.将获取到到的数据保存到数据库
                $.ajax({
                    url:"${pageContext.request.contextPath}/T_sheshiServlet?method=add",
                    data:data.field,  //当前表单里面填写的数据{name:'',name1:''}
                    type:"post",
                    success:function(r){
                        layer.closeAll();
                        //刷新一下table
                        table.reload('test',{
                            page:{
                                curr:1
                            }
                        })
                    },error:function(msg){
                        alert("服务器错误")
                    }
                })
                return false;
            });
        });
    });
</script>
</body>
</html>
